package br.com.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;

import br.com.Dao.CupomDao;
import br.com.Dao.EnderecoDao;
import br.com.Modelo.Endereco;

/**
 * Servlet implementation class buscarCupomJson
 */
@WebServlet("/usarCupom")
public class usar_cupom extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public usar_cupom() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		int id_cup =Integer.parseInt( request.getParameter("optionsRadios"));		
		long id_cliente = Long.parseLong(request.getParameter("id_user"));
		long id_comerciante = Long.parseLong(request.getParameter("id_comerciante"));
		long id_produto = Long.parseLong(request.getParameter("id_produto"));
		String nomePagina = request.getParameter("nome_pagina");
		
		CupomDao dao= new CupomDao();
		
		dao.atualizarUsarCupom(id_cliente, id_comerciante, id_cup);
		
	
     	response.sendRedirect("/plataforma_marketing/products/"+nomePagina+"/"+id_produto);
     	
     	
		
	
	}

}
